<template>
    <uni-popup ref="popup">
        <view class="popup-center">
            <view class="popup-head"><view class="popup-title">提现</view><text class="close-icon cs-icon-guanbi" @click="$refs.popup.close()"></text></view>
            <view class="popup-body">
                <view class="popup-form">
                    <view class="popup-form__item">
                        <view class="popup-form__label">提现金额</view>
                        <view class="popup-form__content">
                            <input v-model="formData.amount" class="popup-form__input" placeholder-class="placeholder" type="digit" placeholder="请输入提现金额" />
                        </view>
                    </view>
                </view>
            </view>
            <view class="popup-footer fill-button flex">
                <button class="btn-reset flex-1" @click="merchant_id = ''">重置</button>
                <button class="btn-primary flex-1" @click="onConfirm">确定</button>
            </view>
        </view>
    </uni-popup>
</template>

<script>
import WxValidate from "@/utils/WxValidate"
export default {
    data() {
        return {
            formData: {
                amount: ""
            },
            validate: ""
        }
    },
    props: ["info"],
    mounted() {
        const rules = {
            amount: { required: true, min: 10 }
        }
        const message = {
            amount: { required: "请输入提现金额", min: "提现金额不能少于10元" }
        }
        this.validate = new WxValidate(rules, message)
    },
    methods: {
        close() {
            this.formData.amount = ""
            this.$refs.popup.close()
        },
        open() {
            this.$refs.popup.open()
        },
        async onConfirm() {
            try {
                if (!this.validate.checkForm(this.formData)) {
                    const error = this.validate.errorList[0]
                    return this.$showToast(error.msg)
                }
                if (this.loading) return
                this.loading = true
                this.$showLoading("请求中")
                const { amount } = this.formData
                const params = { activity_id: this.info.id, amount: amount * 100 }
                await this.$api.withdraw(params)
                this.close()
                this.$emit("loadData")
                await this.$showWaiting("提交成功", 1500)
                this.loading = false
            } catch {
                this.loading = false
            }
        }
    }
}
</script>

<style></style>
